<?
$name='';
if( isset($_GET["u"]) ) {
    $name = $_GET["u"];
} elseif ( isset($_POST["name"]) ) {
    $name = $_POST["name"];
} elseif ( isset($_POST["cn"]) ) {
    $name = $_POST["cn"];
} elseif ( isset($_GET["name"]) ) {
    $name = $_GET["name"];
}
$sr=ldap_search($conn, $GLOBALS["dc"], "(cn=$name)");
$info = ldap_get_entries($conn, $sr);

echo "<table class=framed>";
echo "<tr><td colspan=2 class=tbhead>Användare: ".$info[0]["cn"][0]."</td></tr>";
echo "<tr><td>användarnamn:</td><td>".$info[0]["cn"][0]."</td></tr>";
echo "<input type=\"hidden\" name=\"cn\" value=\"".$info[0]["cn"][0]."\">";
echo "<tr><td>fullständigt namn:</td><td><input class=\"input-box\" type=\"text\" name=\"displayName\" value=\"".utf8_decode($info[0]["displayname"][0])."\"></td></tr>";
//echo "<input type=\"hidden\" name=\"uid\" value=\"$uid\">";
echo "</table>";

echo "<table class=framed>";
echo "<tr><td colspan=2 class=tbhead>Grupphantering</td></tr>";
$groups = getLdapGroups($conn);

// NEW GROUP
echo "<tr><td>lägg till medlemskap:</td><td>\n";
echo "<input type=\"hidden\" name=\"oldGroup\" value=\"".$info[0]["gidnumber"][0]."\">\n";
echo "<select name=\"addToGroup\">\n";

echo '<option value="">';
foreach ($groups as $i) {
        if ($i["gidnumber"][0] != 515) {
                if ($i["gidnumber"][0] != $info[0]["gidnumber"][0])
                        echo "<option value=\"".$i["cn"][0]."\">".$i["cn"][0]."\n";
        }
}
echo "</select></td></tr>\n";
// LIST GROUPS, NOT MAIN GROUP
$groupString='';
for ($i=0; $i < count($groups); $i++) {
        if ($groups[$i]["memberuid"])
                if (in_array($name, $groups[$i]["memberuid"]))
                        if ($groups[$i]["gidnumber"][0] != $info[0]["gidnumber"][0]) {
                                echo "<tr><td>medlem i: </td><td>".$groups[$i]["cn"][0]."</td><td><a href=\"?s=ldap&t=users&u=$name&mod=user&name=$name&delGroup=".$groups[$i]["cn"][0]."&do=1\"><img src=images/delete.png border=0></a></td></tr>";
                                $groupString .= ",".$groups[$i]["cn"][0];

                        }
}
echo "<input type=hidden value=\"$groupString\" name=\"groupString\">";

echo "</table>";
?>
